package MAP_study;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Map_study3 {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("李晨","范冰冰");
        map.put("李鬼","范水水");
        map.put("王狗蛋","范水水");
        Set<Map.Entry<String,String>> set = map.entrySet();
        //用Map中的方法，将map中的entry对象存放到set集合中
        Iterator<Map.Entry<String,String>> it = set .iterator();
        //使用迭代器获取并遍历Set集合
        while(it.hasNext())
        {
            Map.Entry<String,String> entry = it.next();
            //用Entry对象来获取key和value值
            System.out.println("key:"+entry.getKey()+"value:"+entry.getValue());
        }
    }
}
